<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录</title>
</head>
<body>
  <form id="signInForm">
    <div>
      <label for="">用户名<input type="text" name="name"></label>
    </div>
    <div>
      <label for="">密码<input type="password" name="password"></label>
    </div>
    <div>
      <button type="submit">提交</button>
    </div>
  </form>

  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script>
    const $form = $('#signInForm')
    $form.on('submit', e=>{
      e.preventDefault()
      const name = $('input[name=name]').val()
      const password = $('input[name=password').val()
      console.log(name, password)

      $.ajax({
        method: 'POST',
        url: '/sign_in',
        contentType: 'text/html',
        data: JSON.stringify({name, password})
      }).then(() => {
        alert('登录成功')
        location.href = '/home.html'
      }, () => {})
    })
  </script>
</body>
</html>